import 'package:sqflite/sqflite.dart';
import 'package:wangziyi/db/base_db_provider.dart';


import 'package:wangziyi/entity/user_address.dart';

class AddressDao extends BaseDBProvider{

  //表名
  final String name="aa";
  //表主键字段
  final String columnId='id';
  @override
  tableName() {

    return name;
  }

  @override
  tableSqlString() {
   return tableBaseString(name, columnId)+
    '''
    userName text,
    userPhone text,
    userAddress text,
    userDetailedAddress text
    )''';
  }

  //插入一条消息
  Future insert(UserAddress manager)async{
    Database db=await getDataBase();
    return await db.insert(name, toMap(manager));
  }



  //根据id插叙一条消息
// Future<UserAddress> getMessageById(String id) async{
//       Database db=await getDataBase();
//       List<Map<String ,dynamic>> maps=
//       await db.query(name,where: "id=?",whereArgs: [id]);
//       if(maps.length>0){
//         UserAddress UserAddress= UserAddress.fromJson(maps.first);
//         return UserAddress;
//       }
//       return null;
// }


//获取消息列表
// Future<List<UserAddress>> getUserAddressList()async{
//     Database db =await getDataBase();
//     List<Map<String,dynamic>> maps=await db.query(name);
//     if(maps.length>0){
//       List<UserAddress> listPrivince=maps.map((item)=>UserAddress.fromJson(item)).toList();
//       return listPrivince;
//     }
//     return null;
// }
  //
  Map<String,dynamic > toMap(UserAddress msg) {

    Map<String,dynamic > map={


      "userName":msg.userName,
      "userPhone":msg.userPhone,
      "userAddress":msg.userAddress,
      "userDetailedAddress":msg.userDetailedAddress

    };
    return map;

  }


}

